<template>
	<view class="wrap">
		<view class="info">
			<u-cell-group>
				<u-cell-item  title="联系电话" v-model="mobile"></u-cell-item>
			</u-cell-group>
			<view class="number flex flex-between flex-v-center">
				<label for="">
					车牌号
				</label>
				<input type="text" v-model="carNum" @click="done" placeholder="请输入车牌号" placeholder-style="font-family: HiraginoSansGB-W3;font-size: 26rpx;color: #999;" disabled/>
			</view>
		</view>
		<view class="deal">
			<u-checkbox-group>
				<view class="flex flex-h-start flex-v-center">
					<u-checkbox v-model="checked" icon-size="18" :size="36" @change="checkboxChange">
					</u-checkbox>
					<view class="deals flex flex-start">
						<text>我已阅读并同意</text>
						<navigator url=""> 《用户协议》《隐私声明》</navigator>
					</view>
				</view>

			</u-checkbox-group>
		</view>
		<view class="sub flex flex-h-center">
			<text class="flex flex-h-center flex-v-center" @click="createCode">
				生成挪车码
			</text>
		</view>
		<u-keyboard ref="uKeyboard" mode="car" v-model="show" @change="valChange" @backspace="backspace"></u-keyboard>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checked: false,
				carNum:'',
				mobile:'',
				show:false
			}
		},
		onShow() {
		   this.mobile = uni.getStorageSync("mobile");	
		   let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
		   let curRoute = routes[routes.length - 1].route //获取当前页面路由
		   this.url = curRoute;
		    
			  if(!uni.getStorageSync('token')){
				uni.navigateTo({
					url:"./login/login"
				})
				 uni.setStorageSync('url', this.url);
			  }
			  
		},
		methods: {
			checkboxChange(e) {

			},
			done() {
				this.show = true;
			},
			valChange(val) {
				// 将每次按键的值拼接到value变量中，注意+=写法
				this.carNum += val;
				console.log(this.carNum);
			},
			// 退格键被点击
			backspace() {
				// 删除value的最后一个字符
				if (this.carNum.length) this.carNum = this.carNum.substr(0, this.carNum.length - 1);
				console.log(this.carNum);
			},
			createCode() {
				if (this.carNum=='') {
				   this.toastMsg("请输入车牌号");
					return;
				}
				if(!this.checked){
					this.toastMsg("请勾选阅读协议");
					return;
					// return;
				}
				let content = this.mobile+','+this.carNum
				this.$https.request('/cli/qrcode', true, {
					content:content
				}).then((res) => {
					
					if (res.code == 0) {
						this.LoadingMsg("挪车码生成中...");
						setTimeout(function() {
							uni.hideLoading();
							uni.navigateTo({
								url:"./playbill?codeImg="+res.data.qrcode
							})
						}, 1000)
						
			             uni.setStorageSync('codeImg', res.data.qrcode);
					} else if(res.code == '201') {
						this.LoadingMsg("请先登录");
						setTimeout(function() {
							uni.hideLoading();
							uni.navigateTo({
								url:"./login/login"
							})
						}, 1000)
						
			            uni.setStorageSync('url', this.url);
					} else {
						this.LoadingMsg(res.msg);
						setTimeout(function() {
							uni.hideLoading();
						}, 1000)
					}
			
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.wrap {
		.sub {
			padding: 0 35rpx;

			text {
				border-radius: 10rpx;
				background-color: #2A90FF;
				font-family: HiraginoSansGB-W3;
				font-size: 30rpx;
				color: #fff;
				width: 100%;
				height: 90rpx;

			}
		}

		.deal {
			padding: 70rpx 35rpx 50rpx 35rpx;
			.deals{
				text {
					font-family: HiraginoSansGB-W3;
					font-size: 24rpx;
					color: #666;
				}
				navigator{
					font-family: HiraginoSansGB-W3;
					font-size: 24rpx;
					color: #2A90FF;
				}
			}
		}

		.info {
			padding-top: 40rpx;
			.number{
				padding: 0 35rpx;
				height: 106rpx;
				input{
					text-align: right;
				}
			}
		}
	}
</style>
